package com.study.controller;

import com.study.entity.Clazz;
import com.study.entity.ClazzQueryParam;
import com.study.entity.PageBean;
import com.study.entity.Result;
import com.study.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    @GetMapping
    public Result list(ClazzQueryParam param) {
        PageBean pageBean = clazzService.list(param);
        return Result.success(pageBean);
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        clazzService.delete(id);
        return  Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Clazz clazz){
        clazzService.add(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }

    @PutMapping
    public Result update(@RequestBody Clazz clazz){
        clazzService.update(clazz);
        return  Result.success();
    }

    @GetMapping("/list")
    public Result listAll(){
        List<Clazz> clazzes =  clazzService.selectAll();
        return Result.success(clazzes);
    }

}
